<?php


namespace app\adminapi\controller\member;


use app\adminapi\BaseAdminController;
use app\adminapi\dao\member\MemberLevelDao;
use app\adminapi\lists\member\MemberLevelLists;
use app\adminapi\validate\member\MemberLevelValidate;

/**
 * @projectName src
 */
class MemberLevel extends BaseAdminController
{
    public function add()
    {
        $params = (new MemberLevelValidate())->post([
            'level_name',
            'total_consume_money',
            'total_consume_time'
        ])->goCheck('add');
        MemberLevelDao::add($params);
        return $this->success('添加成功', [], 200, 1);
    }

    public function edit()
    {
        $params = (new MemberLevelValidate())->post([
            'id',
            'level_name',
            'total_consume_money',
            'total_consume_time'
        ])->goCheck('edit');
        $result = MemberLevelDao::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 200, 1);
        }
        return $this->fail(MemberLevelDao::getError());
    }

    public function delete()
    {
        $params = (new MemberLevelValidate())->post([
            'id'
        ])->goCheck('delete');
        MemberLevelDao::delete($params);
        return $this->success('删除成功', [], 200, 1);
    }

    public function detail()
    {
        $params = (new MemberLevelValidate())->get([
            'id'
        ])->goCheck('detail');
        $result = MemberLevelDao::detail($params);
        return $this->data($result);
    }

    public function all()
    {
        $result = MemberLevelDao::getAllData();
        return $this->data($result);
    }

    /**
     * 获取列表
     */
    public function lists()
    {
        return $this->dataLists(new MemberLevelLists());
    }

}